package com.zwps.biz.controller.http;

import com.zwps.biz.api.model.dto.permission.api.AddPermissionApiDTO;
import com.zwps.biz.api.model.dto.permission.api.SelectPagePermissionApiDTO;
import com.zwps.biz.api.model.dto.permission.api.UpdatePermissionApiDTO;
import com.zwps.biz.api.model.vo.permission.api.SelectPagePermissionApiVO;
import com.zwps.biz.api.model.vo.permission.api.SelectPermissionApiVO;
import com.zwps.biz.domain.service.PermissionApiService;
import com.zwps.common.controller.CommonController;
import com.zwps.common.controller.response.message.ResponseDataPageMessage;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 接口权限控制层
 * 
 * @ClassName: PermissionApiController
 * @Description: 
 * @author lantf
 * @date 2023年8月22日
 *
 */
@Tag(name = "接口权限管理")
@RestController
@RequestMapping("system/permission_api")
@Validated
public class PermissionApiController extends CommonController {

    @Autowired
    private PermissionApiService permissionApiService;


    @Operation(summary = "分页查询接口权限")
    @GetMapping("page")
    public ResponseDataPageMessage<SelectPagePermissionApiVO> getPermissionApiPage(SelectPagePermissionApiDTO dto) {
        return ResponseDataPageMessage.data(permissionApiService.selectPermissionApiPage(dto));
    }

    @Operation(summary = "新增接口权限")
    @PostMapping("add")
    public void addPermissionApi(@Valid @NotNull @RequestBody AddPermissionApiDTO dto) {
        permissionApiService.addPermissionApi(dto);
    }

    @Operation(summary = "批量删除接口权限")
    @DeleteMapping("{ids}")
    public void deletePermissionApis(@Valid @NotBlank @PathVariable String ids) {
        permissionApiService.deleteBatchPermissionApi(ids);
    }

    @Parameter(name = "id", description = "接口权限ID", in = ParameterIn.PATH)
    @Operation(summary = "修改接口权限信息")
    @PutMapping("{id}")
    public void updatePermissionApi(@Valid @NotBlank @PathVariable String id,
            @Valid @NotNull @RequestBody UpdatePermissionApiDTO dto) {
        permissionApiService.updatePermissionApi(id, dto);
    }
    
    @Operation(summary = "查询所有接口权限")
    @GetMapping("getPermissionApiAll")
    public List<SelectPermissionApiVO> getPermissionApiAll() {
        return permissionApiService.findPermissionApiAll();
    }


    @Operation(summary = "查询接口权限-详情")
    @GetMapping("{id}")
    public SelectPermissionApiVO selectPermissionApi(@Valid @NotBlank @PathVariable String id) {
        return permissionApiService.selectPermissionApi(id);
    }
}
